(function() {
    var $todoForm = $('#todoForm');
    var $todoInput = $('#todoInput');
    var $todoList = $('#todoList');
    var $doneList= $('#doneList');
	var $todoCount= $('#todoCount');
	var $doneCount= $('#doneCount');
	//更新数目
	function count(){
        var len=$todoList.children().length;
        $todoCount.html(len>0?'现有'+len+'项todo list' : '');
        
   }
    $todoForm.submit(function(e){
    	//取消默认行为
		e.preventDefault();
		//获取输入的数据
        var input_value=$todoInput.val();
        //将数据添加到列表中
        $todoList.append('<li><input type="checkbox" class="add"/>&nbsp;'+input_value+'&nbsp;<a href="#" class="todoDelete"></a></li>');
        //数据更新
        $todoInput.val('');
        count();
    });
	//绑定监听，点击添加到已完成列表中
    $todoList.on('click','.add',function(e){
    	$(this).parent().appendTo($doneList);
    	count();
    });
    $doneList.on('click','.add',function(e){
    	$(this).parent().appendTo($todoList);
    	count();
    });
    
    //绑定监听，点击删除该事项
    $todoList.on('click','.todoDelete',function(e){

        $(this).parent().remove();
        count();
    });
    $doneList.on('click','.todoDelete',function(e){

        $(this).parent().remove();
        
    });
})();